﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CMDBExporter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Init();
        }
        private void Init()
        {
            dsComputerList ds = new dsComputerList();
            dsComputerListTableAdapters.vComputerAnyStatusTableAdapter adp = new dsComputerListTableAdapters.vComputerAnyStatusTableAdapter();
            adp.Fill(ds.vComputerAnyStatus);
            gridComputerList.DataSource = ds.vComputerAnyStatus;
        }

        private void bExportExcel_Click(object sender, EventArgs e)
        {
            if (OptionFormat.CheckedIndex == 0)
            {
                Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter exporter = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter();
                SaveFileDialog fdlg = new SaveFileDialog();
                fdlg.Title = "Select Export Excel File";
                fdlg.InitialDirectory = @"c:\";
                fdlg.Filter = "Excel Workbook(*.xlsx)|*.xlsx|Excel 97-2003 Workbook(*.xls)|*.xls";
                fdlg.FilterIndex = 0;
                fdlg.RestoreDirectory = true;
                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    exporter.Export(gridComputerList, fdlg.FileName);
                    MessageBox.Show("Finish");
                }
                exporter.Dispose();
                fdlg.Dispose();
            }
            
        }
    }
}
